package com.example.now_word;

import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;

import com.example.dao.SettingsDao;
import com.example.dao.StudyRecordDao;
import com.example.dao.WordRecordDao;
import com.example.dao.WordDao;
import com.example.utils.GetThemeStyle;
import com.example.utils.MPAndroidBarChart;
import com.github.mikephil.charting.charts.BarChart;

import java.util.List;

public class StatisticsActivity extends AppCompatActivity  implements View.OnClickListener {
    private TextView all_study_wordCount_Text,all_finish_wordCount_Text,
            all_wrong_wordCount_Text,all_highwrong_wordCount_Text,all_flag_wordCount_Text;//文本框显示组件

    private StudyRecordDao studyRecordDao;//数据库处理类
    private WordRecordDao wordRecordDao;
    private WordDao wordDao;

    private BarChart type_finish_and_wrong_count; //各类型的单词统计柱状图

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTheme(GetThemeStyle.getThemeResId(this));
        setContentView(R.layout.activity_statistics);

        //返回工具栏
        androidx.appcompat.widget.Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        ActionBar actionBar=getSupportActionBar();
        if(actionBar!=null){
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setHomeAsUpIndicator(R.drawable.icon_home_back);
        }

        //初始化数据库处理类
        studyRecordDao =new StudyRecordDao(this);
        wordRecordDao =new WordRecordDao(this);
        wordDao=new WordDao(this);
        SettingsDao settingsDao = new SettingsDao(this);

        //初始化文本框组件
        all_study_wordCount_Text=findViewById(R.id.all_study_wordCount);
        all_finish_wordCount_Text=findViewById(R.id.all_finish_wordCount);
        all_wrong_wordCount_Text=findViewById(R.id.all_wrong_wordCount);
        all_highwrong_wordCount_Text=findViewById(R.id.all_highwrong_wordCount);
        all_flag_wordCount_Text=findViewById(R.id.all_flag_wordCount);

        //图形组件初始化
        type_finish_and_wrong_count=findViewById(R.id.type_finish_and_wrong_count);

        init();

    }
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        switch (item.getItemId()){
            case android.R.id.home:
                finish();
        }
        return super.onOptionsItemSelected(item);
    }

    private void  init() {
        //为文本框设置实时更新信息
        all_study_wordCount_Text.setText(wordRecordDao.getAllStudyWordCount() + "个");
        all_finish_wordCount_Text.setText(wordRecordDao.getAllFinishWordCount() + "个");
        all_wrong_wordCount_Text.setText(wordRecordDao.getAllWrongWordCount() + "个");
        all_highwrong_wordCount_Text.setText(wordRecordDao.getAllHighWrongWordCount(1) + "个");
        all_flag_wordCount_Text.setText(wordRecordDao.getAllFlagWordCount() + "个");

        //更新柱状图
        List<List<Float>> lists= wordRecordDao.getTypeInfomation();
        MPAndroidBarChart.setThreeBarChart(type_finish_and_wrong_count,wordDao.getAllType(),lists.get(0),lists.get(1),lists.get(2),"本类型单词数","已背单词数","错误单词数");

    }

    @Override
    public void onClick(View v) {

    }


}